﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EHTSaleManager.Code.Entity;
using System.Data.SqlClient;
using System.Data;
using EHTSaleManager.Code.DAL;

namespace EHTSaleManager.Code.BLL
{
    public class DocumentProvider
    {
        #region Quản lý Document

        public static void UIDocuments(Document theDocument, Boolean isAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUDocuments";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DocumentID", theDocument.DocumentID));
            command.Parameters.Add(new SqlParameter("@Description", theDocument.Description));
            command.Parameters.Add(new SqlParameter("@DocumentUrl", theDocument.DocumentUrl));
            command.Parameters.Add(new SqlParameter("@IsAdd", isAdd));
            DataProvider.ExecuteNoneQuery(command);
        }

        public static void DeleteDocumentByDocumentID(Int32 DocumentID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteDocumentByDocumentID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DocumentID", DocumentID));
            DataProvider.ExecuteNoneQuery(command);
        }

        public static Document GetDocumentByDocumentID(Int32 DocumentID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDocumentByDocumentID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@DocumentID", DocumentID));
            DataSet ds = DataProvider.ExecuteDataSet(command);
            Document theDocument = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theDocument = new Document();
                theDocument.DocumentID = Int32.Parse(ds.Tables[0].Rows[0]["DocumentID"].ToString());
                theDocument.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                theDocument.DocumentUrl = ds.Tables[0].Rows[0]["DocumentUrl"].ToString();
            }

            return theDocument;
        }

        public static DataSet GetDocuments()
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDocuments";
            command.CommandType = CommandType.StoredProcedure;
            DataSet ds = DataProvider.ExecuteDataSet(command);
            return ds;
        }

        public static DataSet GetDocumentsWithPaging(Int32 pageIndex, Int32 pageSize, out Int32 totalRecord)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetDocumentsWithPaging";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@PageIndex", pageIndex));
            command.Parameters.Add(new SqlParameter("@PageSize", pageSize));
            DataSet ds = DataProvider.ExecuteDataSet(command, out totalRecord);
            return ds;
        }


        #endregion
    }
}